import { ApiCall } from "tsrpc";
import { ReqStart, ResStart } from "../../../../shared/master/minGame/searchGift/PtlStart";
import { player } from "../../../../model/fight/body/player";
import app, { xlsxCfgNames } from "../../../../app";
import god from "../../../../god";
import { Tpl_gifts_default, template } from "../../../../shared/master/MsgAction";
import manage_user from "../../../model/manage/manage_user";

export default async function (call: ApiCall<ReqStart, ResStart>) {
    call.succ({})
    let user = call.req._player as player;
    // 装备
    // 技能
    // 随机道具
    if (!call.req.gold) {
        user.callApi('minGame/searchGift/Menu', {})
        return;
    }
    if (call.req.gold <= 1500) {
        call.req.gold = 1500;
    }
    call.req.gold = Math.ceil(call.req.gold);
    let res = user.check_wallet(call.req.gold, 0, [], false, '澳门 · 寻宝', true);
    if (!res.state) {
        return;
    }
    // 根据盲盒总价值 给予相同价值的道具

    let needValue = app.random(call.req.gold * 0.5, call.req.gold * 1.2);
    let random = app.random(1, 7);
    let list: any = []
    let tpl: Tpl_gifts_default = {
        title: "寻宝完成",
        items: []
    }
    switch (random) {
        case 1:
            let duble_equip = (app.random(10, 100))
            list = god.getRandomItems(Math.ceil(needValue / (app.random(10, 100))), `${user.name}·寻宝`, 'Shop_equip', true, true);
            tpl = {
                title: `寻宝完成`,
                items: user.addItems(list)
            }
            user.sendMsg(template.通用奖励, tpl)
            if (duble_equip < 30 && needValue > 10000) {
                manage_user.sendAllMsg(template.default, `恭喜${user.name}!在澳门·寻宝中 获得${list[0].getStyleName()}!`)
            }
            break;
        case 2:
            list = god.getRandomItems(Math.ceil(needValue / (app.random(10, 100))), `${user.name}·寻宝`, 'npcShop_att', true);
            tpl = {
                title: `寻宝完成`,
                items: user.addItems(list)
            }
            user.sendMsg(template.通用奖励, tpl)
            break;
        case 3:
            list = god.getRandomItems(Math.ceil(needValue / (app.random(10, 100))), `${user.name}·寻宝`, 'Shop_skill', true, true);
            tpl = {
                title: `寻宝完成`,
                items: user.addItems(list)
            }
            user.sendMsg(template.通用奖励, tpl)
            break;
        case 4:
            list = god.getRandomItems(Math.ceil(needValue * (app.random(5, 20) / 10)), `${user.name}·寻宝`, 'cfg_shop', true);
            tpl = {
                title: `寻宝完成`,
                items: user.addItems(list)
            }
            user.sendMsg(template.通用奖励, tpl)
            break;
        case 5:
            list = god.getRandomItems(Math.ceil(needValue * (app.random(5, 20) / 10)), `${user.name}·寻宝`, 'cfg_shop', true);
            tpl = {
                title: `寻宝完成`,
                items: user.addItems(list)
            }
            user.sendMsg(template.通用奖励, tpl)
            break;
        case 6:
            list = god.getRandomItems(Math.ceil(needValue * (app.random(5, 20) / 10)), `${user.name}·寻宝`, 'cfg_shop', true);
            tpl = {
                title: `寻宝完成`,
                items: user.addItems(list)
            }
            user.sendMsg(template.通用奖励, tpl)
            break;
        default:
            user.sendMsg(template.default_none, '😭太倒霉了！此次寻宝被海盗抢掉了')
            break;
    }

}